package com.swak.fx.support.ui;

import java.util.List;

import javafx.collections.ObservableList;
import javafx.scene.Node;
import javafx.scene.layout.FlowPane;
import javafx.scene.layout.Priority;
import javafx.scene.layout.StackPane;
import javafx.scene.layout.VBox;

/**
 * UIPanel.
 * 
 * @author 618lf
 */
public class UIPanel extends VBox implements UILifecycle {
	private final String STYLE_CLASS = "ui-panel";
	private final String HEADING_STYLE_CLASS = "ui-panel__heading";
	private final String BODY_STYLE_CLASS = "ui-panel__body";
	private final String ACTIONS_STYLE_CLASS = "ui-panel__actions";
	private final String STYLESHEET = UI.load("css/UIPanel.css");

	private StackPane heading = new StackPane();
	private StackPane body = new StackPane();
	private FlowPane actions = new FlowPane();

	public UIPanel() {
		this.init();
	}

	@Override
	public void initializeParts() {
		this.getStyleClass().addAll(STYLE_CLASS);
		this.heading.getStyleClass().addAll(HEADING_STYLE_CLASS, "title");
		this.body.getStyleClass().add(BODY_STYLE_CLASS);
		this.actions.getStyleClass().add(ACTIONS_STYLE_CLASS);
		this.getChildren().setAll(heading, body, actions);
		VBox.setVgrow(body, Priority.ALWAYS);
	}

	@Override
	public void setupEventHandlers() {
	}

	@Override
	public void setupValueChangedListeners() {
	}

	/***************************************************************************
	*                                                                         *
	* Setters / Getters                                                       *
	*                                                                         *
	**************************************************************************/

	public ObservableList<Node> getHeading() {
		return heading.getChildren();
	}

	/**
	 * set header node
	 *
	 * @param titleContent
	 */
	public void setHeading(Node... titleContent) {
		this.heading.getChildren().setAll(titleContent);
	}

	public ObservableList<Node> getBody() {
		return body.getChildren();
	}

	/**
	 * set body node
	 *
	 * @param body
	 */
	public void setBody(Node... body) {
		this.body.getChildren().setAll(body);
	}

	public ObservableList<Node> getActions() {
		return actions.getChildren();
	}

	/**
	 * set actions of the dialog (Accept, Cancel,...)
	 *
	 * @param actions
	 */
	public void setActions(Node... actions) {
		this.actions.getChildren().setAll(actions);
	}

	public void setActions(List<? extends Node> actions) {
		this.actions.getChildren().setAll(actions);
	}

	// ================================================================================
	// Overridden Methods
	// ================================================================================

	@Override
	public String getUserAgentStylesheet() {
		return STYLESHEET;
	}
}
